home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / N-P / NodeCompilerSrc.cpt / updatenodelist.c < prev   
Text File  |  1989-08-25  |  2KB  |  112 lines

  1. /* Copyright (c) 1987 Michael E. Connick */
  2.  
  3. #include <String.h>
  4. #include <stdio.h>
  5.  
  6. UpdateNodeList()
  7. {
  8.     char    nFile[256], dFile[256], record[513], nodeLine[513], *ptr1;
  9.     char    command, number[20], extension[10], outFile[256];
  10.     int        counter, i;
  11.     FILE    *nfp, *dfp, *ofp;
  12.  
  13.     if(message("Select nodediff file.") == FALSE)
  14.         {
  15.         return;
  16.         }
  17.     if(getfile("TEXT", dFile) == FALSE)
  18.         return;
  19.     if((ptr1 = strchr(dFile, '.')) == NULL)
  20.         {
  21.         message("Invalid nodediff file selected");
  22.         return;
  23.         }
  24.     strcpy(extension, ptr1);
  25.     if((dfp = fopen(dFile,"rb")) == NULL)
  26.         {
  27.         message("UpdateNodeList - Unable to open nodediff file.");
  28.         return;
  29.         }
  30.     if(message("Select nodelist file to be updated.") == FALSE)
  31.         {
  32.         return;
  33.         }
  34.     if(getfile("TEXT", nFile) == FALSE)
  35.         return;
  36.     strcpy(outFile, nFile);
  37.     if((nfp = fopen(nFile,"rb")) == NULL)
  38.         {
  39.         message("UpdateNodeList - Unable to open nodelist file.");
  40.         return;
  41.         }
  42.     if((ofp = fopen("templist","wb")) == NULL)
  43.         {
  44.         message("UpdateNodeList - Unable to open nodelist file.");
  45.         return;
  46.         }
  47.     fgets(record,512,dfp);
  48.     fgets(nodeLine,512,nfp);
  49.     if(strcmp(record, nodeLine) != 0)
  50.         {
  51.         message("Incorrect nodelist/nodediff combination");
  52.         return;
  53.         }
  54.     fseek(nfp, 0L, 0);
  55.     while(fgets(record,512,dfp) != NULL)
  56.         {
  57.         if((ptr1 = strchr(record, '\r')) != NULL)
  58.             *ptr1 = '\0';
  59.         if(strlen(record) == 0)
  60.             continue;
  61.         ptr1 = record;
  62.         if(*ptr1 == 0x0a)
  63.             ptr1++;
  64.         if(strlen(ptr1) == 0)
  65.             continue;
  66.         command = *ptr1++;
  67.         strcpy(number, ptr1);
  68.         counter = atoi(number);
  69.         if(command == 'D')
  70.             {
  71.             for(i = 0; i < counter; i++)
  72.                 {
  73.                 rotateCursor();
  74.                 fgets(nodeLine,512,nfp);
  75.                 }
  76.             }
  77.         else if(command == 'C')
  78.             {
  79.             for(i = 0; i < counter; i++)
  80.                 {
  81.                 fgets(nodeLine,512,nfp);
  82.                 fputs(nodeLine,ofp);
  83.                 }
  84.             }
  85.         else if(command == 'A')
  86.             {
  87.             for(i = 0; i < counter; i++)
  88.                 {
  89.                 rotateCursor();
  90.                 fgets(nodeLine,512,dfp);
  91.                 fputs(nodeLine,ofp);
  92.                 }
  93.             }
  94.         else
  95.             {
  96.             message("Invalid nodediff command");
  97.             return;
  98.             }
  99.         }
  100.     fclose(dfp);
  101.     fclose(nfp);
  102.     fclose(ofp);
  103.     if((ptr1 = strchr(outFile, '.')) != NULL)
  104.         *ptr1 = '\0';
  105.     strcat(outFile, extension);
  106.     rename("templist", outFile);
  107.     SetFileType(outFile,'TEXT');
  108.     SetFileSignature(outFile,'TABY');
  109.     InitCursor();
  110.     message("New nodelist created!");
  111. }
  112.